package com.sunlands.zlcx.usercenter.vo;

import com.sunlands.zlcx.usercenter.domain.VipPrivilegeDO;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * @author shixiaopeng
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@DynamicUpdate
@DynamicInsert
public class VipPrivilegeVO implements Serializable {

    private static final long serialVersionUID = -5211888848079627189L;

    @ApiModelProperty(value = "图片地址")
    private String imageUrl;

    @ApiModelProperty(value = "标题")
    private String title;

    @ApiModelProperty(value = "文案")
    private String content;

    public static VipPrivilegeVO fromDO(VipPrivilegeDO vipPrivilegeDO) {
        if (Objects.isNull(vipPrivilegeDO)) {
            return null;
        }
        VipPrivilegeVO vipPrivilegeVO = new VipPrivilegeVO();
        BeanUtils.copyProperties(vipPrivilegeDO, vipPrivilegeVO);

        return vipPrivilegeVO;
    }

    public static List<VipPrivilegeVO> fromDO(List<VipPrivilegeDO> vipPrivilegeDOList) {
        if (Objects.isNull(vipPrivilegeDOList)) {
            return Collections.emptyList();
        }

        return vipPrivilegeDOList.stream()
                .map(VipPrivilegeVO::fromDO)
                .filter(Objects::nonNull)
                .collect(Collectors.toList());
    }
}
